package main

import (
	"fmt"
	"sort"
)

//sort of map
func main() {
	map1 := make(map[int]int, 10)
	map1[10] = 100
	map1[1] = 13
	map1[4] = 56
	map1[3] = 90
	//这里已经按key进行了排序
	fmt.Println(map1)

	//单独对key进行排序
	var keys []int
	for k := range map1 {
		keys = append(keys, k)
	}
	//这里输出的是乱序的
	// fmt.Println("before sort", keys)
	sort.Ints(keys)
	//key 排序ok
	// fmt.Println("after sort", keys)
	for i, k := range keys {
		fmt.Printf("index?=%v,key=%v,value=%v\n", i, k, map1[k])
	}
}
